home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000024_icon-group-sender _Wed Jul 21 08:48:31 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
2KB
Received: by cheltenham.cs.arizona.edu; Wed, 21 Jul 1993 10:50:24 MST
Message-Id: <9307211546.AA32785@enlil.premenos.sf.ca.us>
From: Ken Walker <kwalker@shara.premenos.sf.ca.us>
Subject: Re: Mysteries of "every"
To: icon-group@cs.arizona.edu
Date: Wed, 21 Jul 93 8:48:31 PDT
In-Reply-To: <706461@MTS.cc.Wayne.edu>; from "Paul_Abrahams@MTS.cc.Wayne.edu" at Jul 20, 93 9:35 pm
Mailer: Elm [revision: 66.25]
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> Paul Abrahams (abrahams@acm.org) writes:
>
> Yet I've looked again at pages 15-16 of the Icon book and I still don't
> get it. The explanation of resumption on p. 15 is in terms of failure,
> and there's no failure in the expression of my example. The description
> of "every" on p. 16 says that "expr1 is first evaluated and then
> repeatedly resumed to produce all its values." I would have thought that
> resuming an expression that doesn't fail would cause it to be
> =completely= reevaluated.
The expression
every <expr>
acts the same as
<expr> & &fail
(unless <expr> contains break or continue). failure and resumption are
two halves of the same thing. When something fails it initiates backtracking
and backtracking ends with something being resumed (or by leaving a bounded
expression). While "every" may not be described in terms of failure, it
does initiate backtracking exactly the way failure does.
To understand what gets recomputed and what does not you need to think
in terms of executation order. It may help to convert an expression into
a postfix notation. Your expression
every retval := 8 * retval + ord(!s) - ord("0")
might be converted into someting like the following. "Normal" execution is
left to right and backtracking is right to left. Backtracking ends as soon
as it finds something to resume. When the resumed operation produces another
value execution continues forward again.
(retval ((((8 retval *) (ord (s !) invoke1)) +) (ord "0" invoke1) -) :=) every
******************************* ^ |
* | |
* --------------------------------------------
not recomputed backtracking loop, recomputed
Does this help?
Ken Walker, kwalker@premenos.sf.ca.us